/**
 * Created by no1 on 2014/8/29.
 */
'use strict';
var F = require('../common/function');
var commMan = require('../common/man');
var C = require('../config/index');
var md5 = require('md5');

module.exports = function (app) {
    var manApiPre = C.manApiPre;

    app.get('/md5/:varmd', function* () {
        var md = this.params.varmd;
        this.body = md5.digest_s(md);
    });


    /*
     @todo API01 创建马甲
     */
    app.post(manApiPre + '/:apiVer/addVest', function*() {
        this.I = yield F.Init(this, [1, 11]);
        if (this.I.errors) {
            this.jsonp = F.returnMsg(400, this.I.errors.msg, this.I.errors.level);
        } else {
            this.jsonp = yield commMan.addVest(this);
        }
    });

    /*
     @todo API02 马甲列表
     */
    app.get(manApiPre + '/:apiVer/vest', function*() {
        this.I = yield F.Init(this, [1, 2]);
        if (this.I.errors) {
            this.jsonp = F.returnMsg(400, this.I.errors.msg, this.I.errors.level);
        } else {
            this.jsonp = yield commMan.vest(this);
        }
    });

    /*
     @todo API03 修改马甲启用状态
     */
    app.post(manApiPre + '/:apiVer/vestStatus', function*() {
        this.I = yield F.Init(this, [1, 11]);
        if (this.I.errors) {
            this.jsonp = F.returnMsg(400, this.I.errors.msg, this.I.errors.level);
        } else {
            this.jsonp = yield commMan.vestStatus(this);
        }
    });

    /*
     @todo API04 马甲发帖统计
     */
    app.get(manApiPre + '/:apiVer/vestThread', function*() {
        this.I = yield F.Init(this, [1, 11]);
        if (this.I.errors) {
            this.jsonp = F.returnMsg(400, this.I.errors.msg, this.I.errors.level);
        } else {
            this.jsonp = yield commMan.vestThread(this);
        }
    });

    /*
     @todo API05 马甲发帖统计明细
     */
    app.get(manApiPre + '/:apiVer/vestThreadDetail', function*() {
        this.I = yield F.Init(this, [1, 11]);
        if (this.I.errors) {
            this.jsonp = F.returnMsg(400, this.I.errors.msg, this.I.errors.level);
        } else {
            this.jsonp = yield commMan.vestThreadDetail(this);
        }
    });

    /*todo API06 后台主题帖操作

     */
    app.post(manApiPre + '/:apiVer/manThread', function*() {
        this.I = yield F.Init(this, [1,2]);
        if (this.I.errors) {
            this.jsonp = F.returnMsg(400, this.I.errors.msg, this.I.errors.level);
        } else {
            this.jsonp = yield commMan.manOperateThread(this);
        }
    });

    /*todo API07 后台回复帖操作

     */
    app.post(manApiPre + '/:apiVer/manPost', function*() {
        this.I = yield F.Init(this, [1]);
        if (this.I.errors) {
            this.jsonp = F.returnMsg(400, this.I.errors.msg, this.I.errors.level);
        } else {
            this.jsonp = yield commMan.manPost(this);
        }
    });

    /*todo API08 切换马甲
     @
     */
    app.post(manApiPre + '/:apiVer/changeVest', function*() {
        this.I = yield F.Init(this, [1]);
        if (this.I.errors) {
            this.jsonp = F.returnMsg(400, this.I.errors.msg, this.I.errors.level);
        } else {
            this.jsonp = yield commMan.changeVest(this);
        }
    });

    /*todo API09 用户列表
     @
     */
    app.get(manApiPre + '/:apiVer/users', function*() {
        this.I = yield F.Init(this, [1]);
        if (this.I.errors) {
            this.jsonp = F.returnMsg(400, this.I.errors.msg, this.I.errors.level);
        } else {
            this.jsonp = yield commMan.users(this);
        }
    });

    /*
     /*todo API10 修改帖子内容
     */
    app.post(manApiPre + '/:apiVer/postEdit', function*() {
        this.I = yield F.Init(this, [1]);
        if (this.I.errors) {
            this.jsonp = F.returnMsg(400, this.I.errors.msg, this.I.errors.level);
        } else {
            this.jsonp = yield commMan.postEdit(this);
        }
    });

    /*
     @todo API11 主题帖修改标签
     */
    app.post(manApiPre + '/:apiVer/threadTags', function*() {
        this.I = yield F.Init(this, [1]);
        if (this.I.errors) {
            this.jsonp = F.returnMsg(400, this.I.errors.msg, this.I.errors.level);
        } else {
            this.jsonp = yield commMan.threadTags(this);
        }
    });

    /*
     @todo API12 某日网站数据
     */
    app.get(manApiPre + '/:apiVer/siteInfo', function*() {
        this.I = yield F.Init(this, [1]);
        if (this.I.errors) {
            this.jsonp = F.returnMsg(400, this.I.errors.msg, this.I.errors.level);
        } else {
            this.jsonp = yield commMan.siteInfo(this);
        }
    });

    /*
     @todo API13 提交升级信息
     */
    app.post(manApiPre + '/:apiVer/appUpdate', function*() {
        this.I = yield F.Init(this, [1]);
        if (this.I.errors) {
            this.jsonp = F.returnMsg(400, this.I.errors.msg, this.I.errors.level);
        } else {
            this.jsonp = yield commMan.appUpdate(this);
        }
    });
    /**
     * @todo API14 编辑标签
     */
    app.post(manApiPre + '/:apiVer/editTag', function*() {
        this.I = yield F.Init(this, [1]);
        if (this.I.errors) {
            this.jsonp = F.returnMsg(400, this.I.errors.msg, this.I.errors.level);
        } else {
            this.jsonp = yield commMan.editTag(this);
        }
    });

    /**
     * @todo API15 添加轮播
     */
    app.post(manApiPre + '/:apiVer/postSlider', function*() {
        this.I = yield F.Init(this, [1]);
        if (this.I.errors) {
            this.jsonp = F.returnMsg(400, this.I.errors.msg, this.I.errors.level);
        } else {
            this.jsonp = yield commMan.postSlider(this);
        }
    });
    /**
     * @todo API16 修改轮播
     */
    app.post(manApiPre + '/:apiVer/editSlider', function*() {
        this.I = yield F.Init(this, [1]);
        if (this.I.errors) {
            this.jsonp = F.returnMsg(400, this.I.errors.msg, this.I.errors.level);
        } else {
            this.jsonp = yield commMan.editSlider(this);
        }
    });
    /**
     * @todo API17 取轮播信息
     */
    app.get(manApiPre + '/:apiVer/getSlider', function*() {
        this.I = yield F.Init(this, [1]);
        if (this.I.errors) {
            this.jsonp = F.returnMsg(400, this.I.errors.msg, this.I.errors.level);
        } else {
            this.jsonp = yield commMan.getSlider(this);
        }
    });
    /**
     * @todo API18 取轮播列表
     */
    app.get(manApiPre + '/:apiVer/getSliderList', function*() {
        this.I = yield F.Init(this, [1]);
        if (this.I.errors) {
            this.jsonp = F.returnMsg(400, this.I.errors.msg, this.I.errors.level);
        } else {
            this.jsonp = yield commMan.getSliderList(this);
        }
    });

    /*
     @todo API19 添加用户自定义标签
     */
    app.post(manApiPre + '/:apiVer/addTag', function*() {
        this.I = yield F.Init(this, [1, 11]);
        if (this.I.errors) {
            this.jsonp = F.returnMsg(400, this.I.errors.msg, this.I.errors.level);
        } else {
            this.jsonp = yield commMan.addTag(this);
        }
    });

    /*
     @todo API20 添加版本升级信息
     */
    app.post(manApiPre + '/:apiVer/addAppUpgrate', function*() {
        this.I = yield F.Init(this, [1]);
        if (this.I.errors) {
            this.jsonp = F.returnMsg(400, this.I.errors.msg, this.I.errors.level);
        } else {
            this.jsonp = yield commMan.addAppUpgrate(this);
        }
    });

    /*
     @todo API21 获取某个版本升级信息
     */
    app.get(manApiPre + '/:apiVer/getAppUpgrate', function*() {
        this.I = yield F.Init(this, [1]);
        if (this.I.errors) {
            this.jsonp = F.returnMsg(400, this.I.errors.msg, this.I.errors.level);
        } else {
            this.jsonp = yield commMan.getAppUpgrate(this);
        }
    });

    /*
     @todo API22 编辑版本升级信息
     */
    app.post(manApiPre + '/:apiVer/editAppUpgrate', function*() {
        this.I = yield F.Init(this, [1]);
        if (this.I.errors) {
            this.jsonp = F.returnMsg(400, this.I.errors.msg, this.I.errors.level);
        } else {
            this.jsonp = yield commMan.editAppUpgrate(this);
        }
    });

    /*
     @todo API23 获取版本升级信息列表
     */
    app.get(manApiPre + '/:apiVer/getAppUpgrateList', function*() {
        this.I = yield F.Init(this, [1]);
        if (this.I.errors) {
            this.jsonp = F.returnMsg(400, this.I.errors.msg, this.I.errors.level);
        } else {
            this.jsonp = yield commMan.getAppUpgrateList(this);
        }
    });

    /**
     * @todo API24 取标签的关系
     */
    app.get(manApiPre + '/:apiVer/getTagRelation', function*() {
        this.I = yield F.Init(this, [1]);
        if (this.I.errors) {
            this.jsonp = F.returnMsg(400, this.I.errors.msg, 3); // 不提醒客户数据格式错误
        } else {
            this.jsonp = yield commMan.getTagRelation(this);
        }
    });

    /**
     * @todo API25 取轮播菜单管理分类
     */
    app.get(manApiPre + '/:apiVer/getSliderType', function*() {
        this.I = yield F.Init(this, [1]);
        if (this.I.errors) {
            this.jsonp = F.returnMsg(400, this.I.errors.msg, 3); // 不提醒客户数据格式错误
        } else {
            this.jsonp = yield commMan.getSliderType(this);
        }
    });

    /**
     * @todo API26 轮播排序
     */
    app.post(manApiPre + '/:apiVer/sortSlider', function*() {
        this.I = yield F.Init(this, [1]);
        if (this.I.errors) {
            this.jsonp = F.returnMsg(400, this.I.errors.msg, 3); // 不提醒客户数据格式错误
        } else {
            this.jsonp = yield commMan.sortSlider(this);
        }
    });

    /**
     * @todo API27 处理投诉
     */
    app.post(manApiPre + '/:apiVer/solveComplain', function*() {
        this.I = yield F.Init(this, [1]);
        if (this.I.errors) {
            this.jsonp = F.returnMsg(400, this.I.errors.msg, 3); // 不提醒客户数据格式错误
        } else {
            this.jsonp = yield commMan.solveComplain(this);
        }
    });

    /**
     * @todo API28 新增模板
     */
    app.post(manApiPre + '/:apiVer/addHtml', function*() {
        this.I = yield F.Init(this, [1]);
        if (this.I.errors) {
            this.jsonp = F.returnMsg(400, this.I.errors.msg, 3); // 不提醒客户数据格式错误
        } else {
            this.jsonp = yield commMan.addHtml(this);
        }
    });

    /**
     * @todo API29 编辑模板
     */
    app.post(manApiPre + '/:apiVer/editHtml', function*() {
        this.I = yield F.Init(this, [1]);
        if (this.I.errors) {
            this.jsonp = F.returnMsg(400, this.I.errors.msg, 3); // 不提醒客户数据格式错误
        } else {
            this.jsonp = yield commMan.editHtml(this);
        }
    });

    /**
     * @todo API30 取模板信息
     */
    app.get(manApiPre + '/:apiVer/getHtml', function*() {
        this.I = yield F.Init(this, [1]);
        if (this.I.errors) {
            this.jsonp = F.returnMsg(400, this.I.errors.msg, this.I.errors.level);
        } else {
            this.jsonp = yield commMan.getHtml(this);
        }
    });
    /**
     * @todo API31 取模板列表
     */
    app.get(manApiPre + '/:apiVer/getHtmlList', function*() {
        this.I = yield F.Init(this, [1]);
        if (this.I.errors) {
            this.jsonp = F.returnMsg(400, this.I.errors.msg, this.I.errors.level);
        } else {
            this.jsonp = yield commMan.getHtmlList(this);
        }
    });

    /**
     * @todo API32 获取又拍云签名
     */
    app.get(manApiPre + '/:apiVer/getSign', function*() {
        this.I = yield F.Init(this, [1]);
        if (this.I.errors) {
            this.jsonp = F.returnMsg(400, this.I.errors.msg, this.I.errors.level);
        } else {
            this.jsonp = yield commMan.getSign(this);
        }
    });

    /**
     * @todo API33 推送友盟广播
     */
    app.post(manApiPre + '/:apiVer/umengBroadcast', function*() {
        this.I = yield F.Init(this, [1, 2, 3,4]);
        if (this.I.errors) {
            this.jsonp = F.returnMsg(400, this.I.errors.msg, this.I.errors.level);
        } else {
            this.jsonp = yield commMan.umengBroadcast(this);
        }
    });

    /**
     * @todo API34 推送友盟广播日志
     */
    app.get(manApiPre + '/:apiVer/umengBroadcast', function*() {
        this.I = yield F.Init(this, [1]);
        if (this.I.errors) {
            this.jsonp = F.returnMsg(400, this.I.errors.msg, this.I.errors.level);
        } else {
            this.jsonp = yield commMan.umengBroadcastLog(this);
        }
    });

    /**
     * @todo API35 帖子列表
     */
    app.get(manApiPre + '/:apiVer/threads', function*() {
        this.I = yield F.Init(this, [1]);
        if (this.I.errors) {
            this.jsonp = F.returnMsg(400, this.I.errors.msg, this.I.errors.level);
        } else {
            this.jsonp = yield commMan.threads(this);
        }
    });

    /**
     * @todo API36 达人申请列表
     */
    app.get(manApiPre + '/:apiVer/talentApplyList', function*() {
        this.I = yield F.Init(this, [1]);
        if (this.I.errors) {
            this.jsonp = F.returnMsg(400, this.I.errors.msg, this.I.errors.level);
        } else {
            this.jsonp = yield commMan.talentApplyList(this);
        }
    });

    /**
     * @todo API37 取一条达人申请信息
     */
    app.get(manApiPre + '/:apiVer/talentApplyInfo', function*() {
        this.I = yield F.Init(this, [1]);
        if (this.I.errors) {
            this.jsonp = F.returnMsg(400, this.I.errors.msg, this.I.errors.level);
        } else {
            this.jsonp = yield commMan.talentApplyInfo(this);
        }
    });

    /**
     * @todo API38 审批达人申请
     */
    app.post(manApiPre + '/:apiVer/answerTalentApply', function*() {
        this.I = yield F.Init(this, [1]);
        if (this.I.errors) {
            this.jsonp = F.returnMsg(400, this.I.errors.msg, this.I.errors.level);
        } else {
            this.jsonp = yield commMan.answerTalentApply(this);
        }
    });

    /**
     * @todo API39 登录日志
     */
    app.get(manApiPre + '/:apiVer/getLoginLog', function*() {
        this.I = yield F.Init(this, [1]);
        if (this.I.errors) {
            this.jsonp = F.returnMsg(400, this.I.errors.msg, this.I.errors.level);
        } else {
            this.jsonp = yield commMan.getLoginLog(this);
        }
    });

    /**
     * @todo API40 获取登录用户地理位置信息
     */
    app.get(manApiPre + '/:apiVer/getUsersGeo', function*() {
        this.I = yield F.Init(this, [1]);
        if (this.I.errors) {
            this.jsonp = F.returnMsg(400, this.I.errors.msg, this.I.errors.level);
        } else {
            this.jsonp = yield commMan.getUsersGeo(this);
        }
    });
    /**
     * @todo API41 统计报表
     */
    app.get(manApiPre + '/:apiVer/siteReport', function*() {
        this.I = yield F.Init(this, [1, 2, 3, 4]);
        if (this.I.errors) {
            this.jsonp = F.returnMsg(400, this.I.errors.msg, this.I.errors.level);
        } else {
            this.jsonp = yield commMan.siteReport(this);
        }
    });

    /**
     * @todo API42 活动统计报表
     */
    app.get(manApiPre + '/:apiVer/activityReport', function*() {
        this.I = yield F.Init(this, [1, 2, 3]);
        if (this.I.errors) {
            this.jsonp = F.returnMsg(400, this.I.errors.msg, this.I.errors.level);
        } else {
            this.jsonp = yield commMan.activityReport(this);
        }
    });

    /**
     * @todo API43 帖子类别管理
     */
    app.post(manApiPre + '/:apiVer/threadCategoryInfo', function*() {
        this.I = yield F.Init(this, [1, 2, 3, 4, 5]);
        if (this.I.errors) {
            this.jsonp = F.returnMsg(400, this.I.errors.msg, this.I.errors.level);
        } else {
            this.jsonp = yield commMan.threadCategoryInfo(this);
        }
    });

    // 大众点评数据
    app.get(manApiPre + '/:apiVer/getWatsonsGeo', function*() {
        this.I = yield F.Init(this, [1, 2, 3, 4, 5]);
        if (this.I.errors) {
            this.jsonp = F.returnMsg(400, this.I.errors.msg, this.I.errors.level);
        } else {
            this.jsonp = yield commMan.getWatsonsGeo(this);
        }
    });

    // 屈臣氏数据
    app.get(manApiPre + '/:apiVer/getWatsonsGeo2', function*() {
        this.I = yield F.Init(this, [1]);
        if (this.I.errors) {
            this.jsonp = F.returnMsg(400, this.I.errors.msg, this.I.errors.level);
        } else {
            this.jsonp = yield commMan.getWatsonsGeo2(this);
        }
    });

    app.get(manApiPre + '/:apiVer/testgchan', function*() {
        this.I = yield F.Init(this, [13]);
        if (this.I.errors) {
            this.jsonp = F.returnMsg(400, this.I.errors.msg, this.I.errors.level);
        } else {
            if (C.env != 'production') { // 仅为测试环境才执行
                this.jsonp = yield commMan.testFun(this);
            }
        }
    });


    /**
     * @todo API44 	修改帖时,帖子图片上传成功后的Callback
     */
    app.post(manApiPre + '/:apiVer/postEditImgCallback', function*() {
        this.I = yield F.Init(this, [1]);
        if (this.I.errors) {
            this.jsonp = F.returnMsg(400, this.I.errors.msg, this.I.errors.level);
        } else {
            this.jsonp = yield commMan.postEditImgCallback(this);
        }
    });


    /**
     @todo API45 修改帖子分类
     */
    app.post(manApiPre+'/:apiVer/threadCategory',function*(){
        this.I = yield F.Init(this,[1]);
        if(this.I.errors){
            this.jsonp = F.returnMsg(400, this.I.errors.msg, this.I.errors.level);
        }else{
            this.jsonp = yield commMan.threadCategory(this);
        }
    });

    /**
     @todo API46 后台获取o2o第一二级分类
     */
    app.post(manApiPre+'/:apiVer/geto2oCate',function*(){
        this.I = yield F.Init(this,[1]);
        if(this.I.errors){
            this.jsonp = F.returnMsg(400, this.I.errors.msg, this.I.errors.level);
        }else{
            this.jsonp = yield commMan.geto2oCate();
        }
    });

    /**
     @todo API47 添加o2o分类第三级标签
     */
    app.post(manApiPre+'/:apiVer/addo2oTag',function*(){
        this.I = yield F.Init(this,[1]);
        if(this.I.errors){
            this.jsonp = F.returnMsg(400, this.I.errors.msg, this.I.errors.level);
        }else{
            this.jsonp = yield commMan.addo2oTag(this);
        }
    });

    /**
     @todo API48 添加瓷肌百科页面API
     */
    app.post(manApiPre+'/:apiVer/ciJiWiki',function*(){
        this.I = yield F.Init(this,[1,2,3,4,5]);
        if(this.I.errors){
            this.jsonp = F.returnMsg(400, this.I.errors.msg, this.I.errors.level);
        }else{
            this.jsonp = yield commMan.ciJiWiki(this);
        }
    });
};

